export default {
  data() {
    //身份证校验
    let validateIdCard = (rule, value, callback)=>{
      // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
      let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      if (value !== null && value !== "" && reg.test(value) === false) {
        console.log(value)
        callback(new Error('身份证号码不合法'));
      } else {
        callback();
      }
    };
    //手机号校验
    let validatePhone = (rule, value, callback)=>{
      let reg = /^1[3-9]\d{9}$/;

      if (value !== null && value !== "" && reg.test(value) === false) {
        callback(new Error('手机号不合法'));
      } else {
        callback();
      }
    };
    //校验统一社会信用代码
    let isSocialCreditCode = (rule, value, callback)=>{
      // 前置条件即校验规则的第1至5要求
      const pattern = /^([1-9ANY])([1-9])([0-9]{6})([0-9A-HJ-NP-RT-UW-Y]{10})$/;
      if (!pattern.test(value)){
        callback(new Error('统一社会信用代码不合法'));
      }
      // 定义求模基数31
      const MODE_BASE = 31;
      // 空字符串
      const EMPTY_STR= "";
      // 代码字符数组, 其下标作为代码字符数值
      const CHAR_CODES = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'T', 'U', 'W', 'X', 'Y'];
      // 各位置序号上的加权因子
      const WEIGHT_FACTORS = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];
      // 初始化一个与信用代码等长的空的代码字符数值数组
      // 用于和加权因子进行乘积求和运算
      let values = new Array(value.length);
      // 初始化求和值
      let sum = 0;
      // 将信用代码字符串转换为代码字符数值数组
      value.split(EMPTY_STR).forEach((item, index) => values[index] = CHAR_CODES.findIndex(elem => elem === item));
      // 删除最后一位元素(第18位不参与求和计算)
      const endValue = values.pop();
      // 将字符数组数值逐个元素与加权因子乘积求和
      WEIGHT_FACTORS.forEach((item, index) => sum += item * values[index]);
      // 换算校验代码字符
      // let checkCode = CHAR_CODES[MODE_BASE - sum % MODE_BASE];
      // return val.substring(17, 18) === checkCode;
      // 不换算回字符了，直接用第18位的数值进行比较
      if(endValue === (MODE_BASE - sum % MODE_BASE)){
        callback();
      }else{
        callback(new Error('统一社会信用代码不合法'));
      }
    };
    return {
      customFields: [{
        title: '人员组件',
        list: [{
          label: '姓名',
          prop: 'name',
          span: 24,
          minlength: 2,
          icon: 'icon-oa',
          display: true
        }, {
          label: '性别',
          prop: 'sex',
          span: 24,
          type: "radio",
          dicData: [{
            label: '男',
            value: 0
          }, {
            label: '女',
            value: 1
          }],
          icon: 'icon-oa',
          display: true
        }, {
          label: '身份证号码',
          prop: 'idCard',
          span: 24,
          minlength: 15,
          icon: 'icon-oa',
          rules: [{ validator: validateIdCard, trigger: 'blur' }],
          display: true
        }, {
          label: '手机号码',
          prop: 'phone',
          span: 24,
          minlength: 11,
          icon: 'icon-oa',
          rules: [{ validator: validatePhone, trigger: 'blur' }],
          display: true
        }, {
          label: '住址',
          prop: 'address',
          span: 24,
          type: 'textarea',
          icon: 'icon-oa',
          display: true
        }]
      }, {
        title: '企业组件',
        list: [{
          label: '企业名称',
          prop: 'enterpriseName',
          span: 24,
          icon: 'icon-oa',
          display: true
        }, {
          label: '统一社会信用代码',
          prop: 'unifiedSocialCreditCode',
          span: 24,
          icon: 'icon-oa',
          rules: [{ validator: isSocialCreditCode, trigger: 'blur' }],
          display: true
        }, {
          label: '法人姓名',
          prop: 'legalPersonName',
          span: 24,
          minlength: 2,
          icon: 'icon-oa',
          display: true
        }, {
          label: '法人身份证号',
          prop: 'legalPersonIdCard',
          span: 24,
          rules: [{ validator: validateIdCard, trigger: 'blur' }],
          icon: 'icon-oa',
          display: true
        }, {
          label: '办公电话',
          prop: 'officeTelephone',
          span: 24,
          icon: 'icon-oa',

          display: true
        }, {
          label: '企业地址',
          prop: 'businessAddress',
          span: 24,
          type: 'textarea',
          icon: 'icon-oa',
          display: true
        }]
      }, {
        title: '通用配置组件',
        list: [{
          type: 'table',
          label: '表格选择器',
          display: true,
          icon: 'icon-table',
          span: 24,
          children: {
            border: true,
            searchMenuSpan: 6,
            searchIcon: true,
            column: [],
            props: {
              url: '',
              method: 'get',
              rowKey: 'id',
              needPage: true,
              currentPageKey: 'current',
              pageSizeKey: 'size',
              totalKey: 'total',
              recordsKey: 'records',
              resKey: 'data.data',
              auto: true
            }
          },
          formatter: function formatter(row) {
            return row.name;
          },
          props: {
            label: 'name',
            value: 'id'
          },
        },{
          type: 'title',
          span: 24,
          display: true,
          icon: 'icon-title',
          styles: {
            fontSize: '18px',
            color: '#000'
          },
          labelWidth: '0px',
          label: '标题',
          value: '标题'
        },{
          label: '上传',
          type: 'upload',
          propsHttp: {
            res: 'data',
            url: 'link',
            name: 'originalName'
          },
          action: '/api/blade-resource/oss/endpoint/put-file',
          display: true,
          span: 24,
          canvasOption: { text: ' ' },
          icon: 'icon-upload',
          showFileList: true,
          multiple: true,
          limit: 10,
          headersConfig: [],
          dataConfig: []
        }, {
          type: 'select',
          label: '下拉选择器',
          icon: 'icon-select',
          dicData: [],
          dicUrl: '/api/blade-system/dict/dictionary?code=',
          props: {
            label: "dictValue",
            value: "dictKey"
          },
          dicOption: 'remote',
          span: 24,
          display: true,
        }, {
          component: 'AvueUeditor',
          label: '富文本',
          icon: 'icon-richtext',
          span: 24,
          display: true,
          options: {
            action: '/api/blade-resource/oss/endpoint/put-file',
            oss: '',
            props: {
              res: 'data',
              url: 'link',
            },
            ali: {},
            qiniu: {}
          },
        },{
          label: '部门树',
          type: 'tree',
          prop: 'orgTree',
          dicUrl: '/api/blade-system/dept/tree',
          span: 24,
          props: {
            label: "title",
            value: "id"
          },
          leafOnly: true,
          multiple: true,
          dataType: 'string',
          icon: 'icon-oa',
          display: true
        }, {
          label: '人员选择',
          component: 'formUserSelect',
          span: 24,
          params: {
            checkType: 'checkbox'
          },
          icon: 'icon-oa',
          display: true
        },{
          label: '人员树',
          type: 'tree',
          prop: 'userTree',
          dicUrl: 'api/blade-user/userTree',
          span: 24,
          props: {
            label: "name",
            value: "id"
          },
          leafOnly: true,
          multiple: true,
          dataType: 'string',
          icon: 'icon-oa',
          display: true
        }]
      }]
    }
  }
}
